package com.warm.base.design.b_memento.mult;

import java.util.ArrayList;
import java.util.List;

/**
 * @Date: 2019/11/28 10:21
 * @Author: LChuang
 * @Description:
 */
public class MOriginator {

    private List<String> states;

    public MOriginator(){
        states = new ArrayList<>();
    }

    /**
     * 工厂方法，返还一个新的备忘录对象
     */
    public MMemento createMemento(){
        return new MMemento(states);
    }

    /**
     * 将发起人恢复到备忘录对象记录的状态上
     */
    public void restoreMMemento(MMemento mMemento){
        states = mMemento.getStates();
    }

    public void setState(String state){
        states.add(state);
    }

    public void printStates(){
        for (String state : states){
            System.out.println(state);
        }
    }
}
